package com.zhengxin.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zhengxin.entity.User;
import com.zhengxin.mapper.UserMapper;
import com.zhengxin.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RegisterServiceImpl implements RegisterService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public String register(JSONObject jsonObject) {

        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getName, jsonObject.getString("name"));
        User u = userMapper.selectOne(queryWrapper);
        if (u == null) {
            User user = new User();
            user.setName(jsonObject.getString("name"));
            user.setPassword(jsonObject.getString("password"));
            user.setMailBox(jsonObject.getString("mailBox"));
            user.setPhoneNum(jsonObject.getString("phoneNum"));
            userMapper.insert(user);
            return "1";
        } else {
            return "0";
        }
    }
}
